<?php

class CommonAction extends Action {


    public function _initialize() {
        $this->setLayout();
    }

   

    function setLayout() {
        $layout = $this->_get('layout');
        if ($layout) {
            C('LAYOUT_NAME', 'Layout/' . $layout);
        }
        $this->assign('layout_name', C('LAYOUT_NAME'));
    }

   

    /**
     * 发送api 请求
     * @param array $data 要传递的参数
     * @param string $url 响应地址
     * @access protected
     * @return bool
     */
    protected function sendRuquest($data, $url, $timeout = 1) {
        $data = http_build_query($data);
        $opts = array(
            'http' => array(
                'method' => 'POST',
                'header' => "Content-type: application/x-www-form-urlencoded\r\n" .
                "Content-Length: " . strlen($data) . "\r\n",
                'timeout' => $timeout,
                'content' => $data
            ),
        );

        $context = stream_context_create($opts);
        $html = file_get_contents($url, false, $context);
        debug($url . '?' . $data);
        if ($html) {
            echo $html;
        } else {
            //$this->error('相应超时');
        }
    }


}
